package com.tts.controller;

import com.tts.annotation.OperationLog;
import com.tts.dto.ApiResponse;
import com.tts.entity.BorrowRecord;
import com.tts.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/borrows")
@CrossOrigin
public class BorrowController {

    @Autowired
    private BorrowService borrowService;

    @GetMapping
    public ApiResponse<List<BorrowRecord>> getCurrentUserBorrowRecords() {
        return ApiResponse.success(borrowService.getCurrentUserBorrowRecords());
    }

    @PostMapping("/borrow/{bookId}")
    @OperationLog(operation = "BORROW_BOOK", description = "借阅图书")
    public ApiResponse<BorrowRecord> borrowBook(@PathVariable Long bookId) {
        return ApiResponse.success(borrowService.borrowBook(bookId));
    }

    @PostMapping("/return/{recordId}")
    @OperationLog(operation = "RETURN_BOOK", description = "归还图书")
    public ApiResponse<BorrowRecord> returnBook(@PathVariable Long recordId) {
        return ApiResponse.success(borrowService.returnBook(recordId));
    }
} 